package com.jzt.jk.open.api.manage.infrastructure.common;

import com.jzt.jk.open.api.manage.infrastructure.common.config.GlobalConfig;
import com.jzt.jk.open.api.manage.infrastructure.common.interceptor.AuthInterceptor;
import com.jzt.jk.open.api.manage.infrastructure.common.interceptor.AuthorizationInterceptor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 作者：lizw <br/>
 * 创建时间：2021/01/21 10:51 <br/>
 */
@EnableConfigurationProperties(GlobalConfig.class)
@Configuration
public class WebConfig implements WebMvcConfigurer {
    private final GlobalConfig globalConfig;

    public WebConfig(GlobalConfig globalConfig) {
        this.globalConfig = globalConfig;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AuthInterceptor(globalConfig)).addPathPatterns("/*");
        registry.addInterceptor(new AuthorizationInterceptor(globalConfig)).addPathPatterns("/*");
    }
}
